package fh.jz.kafkastarter.mq.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @author JiangZhe  2021-12-17
 */
public class KafkaDelayConstantsUtil {

    public static final Map<String, Long> delayToMap = new HashMap<>();
    static {
        delayToMap.put("DELAY_TOPIC_FIVE_SECOND_TOPIC", 5000L);
        delayToMap.put("DELAY_TOPIC_HALF_MINUTE_TOPIC", 30000L);
        delayToMap.put("DELAY_TOPIC_ONE_MINUTE_TOPIC", 60000L);
        delayToMap.put("DELAY_TOPIC_FIVE_MINUTE_TOPIC", 300000L);
        delayToMap.put("DELAY_TOPIC_TEN_MINUTE_TOPIC", 600000L);
        delayToMap.put("DELAY_TOPIC_HALF_HOUR_TOPIC", 1800000L);
        delayToMap.put("DELAY_TOPIC_ONE_HOUR_TOPIC", 3600000L);
    }

    public static final String DELAY_TOPIC_FIVE_SECOND_TOPIC = "DELAY_TOPIC_FIVE_SECOND_TOPIC";
    public static final String DELAY_TOPIC_HALF_MINUTE_TOPIC = "DELAY_TOPIC_HALF_MINUTE_TOPIC";
    public static final String DELAY_TOPIC_ONE_MINUTE_TOPIC = "DELAY_TOPIC_ONE_MINUTE_TOPIC";
    public static final String DELAY_TOPIC_FIVE_MINUTE_TOPIC = "DELAY_TOPIC_FIVE_MINUTE_TOPIC";
    public static final String DELAY_TOPIC_TEN_MINUTE_TOPIC = "DELAY_TOPIC_TEN_MINUTE_TOPIC";
    public static final String DELAY_TOPIC_HALF_HOUR_TOPIC = "DELAY_TOPIC_HALF_HOUR_TOPIC";
    public static final String DELAY_TOPIC_ONE_HOUR_TOPIC = "DELAY_TOPIC_ONE_HOUR_TOPIC";


    public static Long getTimestamp(String topic) {
        return Optional.ofNullable(delayToMap.entrySet().stream().filter(entry -> entry.getKey().equals(topic)).findFirst().get().getValue()).orElse(null);
    }


}
